{extend name='admin@main'}

{block name="content"}

{include file='store@state/form_style'}

<form onsubmit="return false;" id="GoodsForm" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off">

    <div class="layui-card-body think-box-shadow padding-left-40" >

        <div class="layui-form-item layui-row layui-col-space15" >
            <label class="layui-col-xs3 relative">
                <span class="color-green">优惠券分类</span>
                <select class="layui-select" required name="cate_id" lay-search>
                    {foreach $cates as $cate}
                    {if isset($vo.cate_id) and $vo.cate_id eq $cate.id}
                    <option selected value="{$cate.id}">{$cate.id} - {$cate.title|default=''}</option>
                    {else}
                    <option value="{$cate.id}">{$cate.id} - {$cate.title|default=''}</option>
                    {/if}
                    {/foreach}
                </select>
            </label>

            <label class="layui-col-xs3 relative">
                <span class="color-green">优惠券所属门店</span>
                <select class="layui-select" required name="shop_id" lay-search>
                    {if isset($vo.shop_id) and $vo.shop_id eq 0}
                    <option  value="0" selected >任意门店 超级优惠券</option>
                    {else}
                    <option  value="0"  >任意门店 超级优惠券</option>
                    {/if}

                    {foreach $shop as $cate}
                    {if isset($vo.shop_id) and $vo.shop_id eq $cate.id}
                    <option selected value="{$cate.id}">{$cate.title|default=''}</option>
                    {else}
                    <option value="{$cate.id}">{$cate.title|default=''}</option>
                    {/if}
                    {/foreach}
                </select>
            </label>

            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券名称</span>
                <input name="title" required class="layui-input" placeholder="请输入优惠券名称" value="{$vo.title|default=''}">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券价格</span>
                <input name="price"  class="layui-input" placeholder="请输入优惠券价格" value="{$vo.price|default=''}">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券总数量</span>
                <input name="all_num"  class="layui-input" placeholder="请输入优惠券总数量" value="{$vo.all_num|default=''}">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券满减档位</span>
                <input name="full_cut"  class="layui-input" placeholder="请输入优惠券满减档位" value="{$vo.full_cut|default=''}">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券有效期天数</span>
                <input name="dates"  class="layui-input" placeholder="请输入优惠券有效期天数" value="{$vo.dates|default=''}">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券使用开始--结束时间</span>
                <input data-date-range name="range_time" value="{$vo.range_time|default=''}"  placeholder="请选择优惠券使用开始--结束时间" class="layui-input">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">优惠券备注</span>
                <input name="beizhu" value="{$vo.beizhu|default=''}"  placeholder="请填写备注" class="layui-input">
            </label>
            <label class="layui-col-xs9 relative" style="width:100%">
                <span class="color-green">使用备注</span>
                <input name="use_remark"  class="layui-input" placeholder="请输入使用备注" value="{$vo.use_remark|default=''}">
            </label>
        </div>


        <div class="layui-form-item">
            <span class="color-green label-required-prev">LOGO</span>
            <table class="layui-table">
                <thead>
                <tr>
                    <th class="text-left">LOGO</th>
                    <th class="text-left" style="display: none">展示优惠券</th>
                </tr>
                <tr>
                    <td width="90px" class="text-left"><input name="logo" type="hidden" value="{$vo.logo|default=''}"></td>
                    <td width="auto" class="text-left" style="display: none"><input name="image" type="hidden" value="{$vo.image|default=''}"></td>
                </tr>
                </thead>
            </table>
            <script>$('[name="logo"]').uploadOneImage(), $('[name="image"]').uploadMultipleImage()</script>
        </div>



        <div class="layui-form-item block" style="display:block !important;">
            <span class="label-required-prev color-green">使用规则</span>
            <textarea name="content">{$vo.content|default=''|raw}</textarea>
        </div>

        <div class="layui-form-item text-center">
            {notempty name='vo.id'}<input type="hidden" name="id" value="{$vo.id}">{/notempty}
            <button class="layui-btn layui-btn-danger" ng-click="hsitoryBack()" type="button">取消编辑</button>
            <button class="layui-btn" type="submit">保存</button>
        </div>

    </div>
</form>
{/block}

{block name='script'}
<script>
    window.form.render();
    require(['ckeditor', 'angular'], function () {
        window.createEditor('[name="content"]', {height: 500});
        var app = angular.module("GoodsForm", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        function callback($rootScope) {
            // 返回列表
            $rootScope.hsitoryBack = function () {
                $.msg.confirm('确定要取消编辑吗？', function (index) {
                    history.back(), $.msg.close(index);
                });
            };
            // 设置默认值
            $rootScope.setValue = function (key, type, value, call) {
                $rootScope.maps[key] || ($rootScope.maps[key] = {});
                return $rootScope.maps[key][type] = eval(call.replace('_', "'" + value + "'"));
            };
            // 读取默认值
            $rootScope.getValue = function (key, callback) {
                if (typeof callback === 'function') {
                    return callback($rootScope.maps[key] || {});
                }
                return {};
            };
            // 去除空白字符
            $rootScope.trimSpace = function (value) {
                return (value + '').replace(/\s*/ig, '');
            };
        }
    })
</script>
{/block}